package com.SFA.ProductShow;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.FrameWork.DB.DataProvider;
import com.FrameWork.Entity.ImagesEntity;
import com.FrameWork.Utils.Utils;
import com.SFA.R;

import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteCursor;

public class ProductPhotoList {
	
	public static List<ImagesEntity> getPhotoInfoList(Context context, int id){
		SQLiteCursor cursor = null;
		List<ImagesEntity> list = new ArrayList<ImagesEntity>();;
		list.clear();
		try {
			String sql = context.getString(R.string.sql_ProductPhotoList) + id;
			cursor = DataProvider.Instance(context).Query(sql);
			while(cursor.moveToNext()){
				ImagesEntity ie = new ImagesEntity();
				ie.setId(cursor.getInt(cursor.getColumnIndex("ID")));
				ie.setProductId(cursor.getInt(cursor.getColumnIndex("PRODUCT_ID")));
				ie.setName(cursor.getString(cursor.getColumnIndex("PHOTO_ID")));
				File fileName = new File(Utils.BuildFilePath("/" + Utils.ImageFolder + "/" + ie.getName()));
				if(fileName.exists())
				{
					ie.setUrl(fileName.getPath());
					list.add(ie);
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			if (cursor != null) {
				cursor.close();
				cursor = null;
			}
		}
		return list;
	}
}
